﻿using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient
{
    // Token: 0x02000DF4 RID: 3572
    internal class XLevelScriptMgr : XSingleton<XLevelScriptMgr>
    {
        // Token: 0x0600C124 RID: 49444 RVA: 0x0028E7B4 File Offset: 0x0028C9B4
        public void RunScript(string funcName)
        {
            XSingleton<XDebug>.singleton.AddGreenLog("add script ", funcName, null, null, null, null);
            if (this._LevelScripts.ContainsKey(funcName))
            {
                if (this._CmdQueue != null && this._CmdQueue.Count > 0)
                {
                    XSingleton<XDebug>.singleton.AddGreenLog("script function append", null, null, null, null, null);
                }
                if (this._CmdQueue.Count == 0)
                {
                    this._currentCmd = null;
                }
                List<LevelCmdDesc> list = this._LevelScripts[funcName];
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Reset();
                    this._CmdQueue.Add(list[i]);
                }
                this.Update();
            }
        }

        // Token: 0x0600C125 RID: 49445 RVA: 0x0028E890 File Offset: 0x0028CA90
        public bool IsCurrentCmdFinished()
        {
            if (this._currentCmd == null)
            {
                return true;
            }
            return this._currentCmd.state == XCmdState.Cmd_Finished;
        }

        // Token: 0x0600C126 RID: 49446 RVA: 0x0028E8CA File Offset: 0x0028CACA
        public void ClearWallInfo()
        {
            this._LevelInfos.Clear();
        }

        // Token: 0x0600C127 RID: 49447 RVA: 0x0028E8DC File Offset: 0x0028CADC
        public void PreloadLevelScript(string file)
        {
            this.Reset();
            this.ClearWallInfo();
            Stream stream = XSingleton<XResourceLoaderMgr>.singleton.ReadText("Table/" + file, ".txt", true);
            StreamReader streamReader = new StreamReader(stream);
            string key = "";
            for (; ; )
            {
                string text = streamReader.ReadLine();
                //bool flag = text == null;
                if (text == null)
                {
                    break;
                }
                text = text.Trim();
                //bool flag2 = text.StartsWith("func:");
                if (text.StartsWith("func:"))
                {
                    string text2 = text.Substring(5);
                    List<LevelCmdDesc> value = new List<LevelCmdDesc>();
                    this._LevelScripts.Add(text2, value);
                    key = text2;
                }
                //bool flag3 = text.StartsWith("talkl");
                if (text.StartsWith("talkl"))
                {
                    string[] array = text.Split(XGlobalConfig.TabSeparator);
                    LevelCmdDesc levelCmdDesc = new LevelCmdDesc();
                    levelCmdDesc.cmd = LevelCmd.Level_Cmd_TalkL;
                    levelCmdDesc.Param.Add(array[1]);
                    levelCmdDesc.Param.Add(array[2]);
                    if (array.Length > 3)
                    {
                        levelCmdDesc.Param.Add(array[3]);
                    }
                    this._LevelScripts[key].Add(levelCmdDesc);
                }
                else if (text.StartsWith("talkr"))
                {
                    string[] array2 = text.Split(XGlobalConfig.TabSeparator);
                    LevelCmdDesc levelCmdDesc2 = new LevelCmdDesc();
                    levelCmdDesc2.cmd = LevelCmd.Level_Cmd_TalkR;
                    levelCmdDesc2.Param.Add(array2[1]);
                    levelCmdDesc2.Param.Add(array2[2]);
                    if (array2.Length > 3)
                    {
                        levelCmdDesc2.Param.Add(array2[3]);
                    }
                    this._LevelScripts[key].Add(levelCmdDesc2);
                }
                else if (text.StartsWith("stoptalk"))
                {
                    LevelCmdDesc levelCmdDesc3 = new LevelCmdDesc();
                    levelCmdDesc3.cmd = LevelCmd.Level_Cmd_Notalk;
                    this._LevelScripts[key].Add(levelCmdDesc3);
                }
                else if (text.StartsWith("addbuff"))
                {
                    string[] array3 = text.Split(XGlobalConfig.TabSeparator);
                    if (array3.Length >= 4)
                    {
                        LevelCmdDesc levelCmdDesc4 = new LevelCmdDesc();
                        levelCmdDesc4.cmd = LevelCmd.Level_Cmd_Addbuff;
                        levelCmdDesc4.Param.Add(array3[1]);
                        levelCmdDesc4.Param.Add(array3[2]);
                        levelCmdDesc4.Param.Add(array3[3]);
                        this._LevelScripts[key].Add(levelCmdDesc4);
                    }
                }
                else if (text.StartsWith("removebuff"))
                {
                    string[] array4 = text.Split(XGlobalConfig.TabSeparator);
                    if (array4.Length >= 3)
                    {
                        LevelCmdDesc levelCmdDesc5 = new LevelCmdDesc();
                        levelCmdDesc5.cmd = LevelCmd.Level_Cmd_Removebuff;
                        levelCmdDesc5.Param.Add(array4[1]);
                        levelCmdDesc5.Param.Add(array4[2]);
                        this._LevelScripts[key].Add(levelCmdDesc5);
                    }
                }
                else if (text.StartsWith("hidebillboard"))
                {
                    string[] array5 = text.Split(XGlobalConfig.TabSeparator);
                    if (array5.Length >= 3)
                    {
                        LevelCmdDesc levelCmdDesc6 = new LevelCmdDesc();
                        levelCmdDesc6.cmd = LevelCmd.Level_Cmd_HideBillboard;
                        levelCmdDesc6.Param.Add(array5[1]);
                        levelCmdDesc6.Param.Add(array5[2]);
                        this._LevelScripts[key].Add(levelCmdDesc6);
                    }
                }
                else if (text.StartsWith("changebody"))
                {
                    string[] array6 = text.Split(XGlobalConfig.TabSeparator);
                    if (array6.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc7 = new LevelCmdDesc();
                        levelCmdDesc7.cmd = LevelCmd.Level_Cmd_ChangeBody;
                        levelCmdDesc7.Param.Add(array6[1]);
                        this._LevelScripts[key].Add(levelCmdDesc7);
                    }
                }
                else if (text.StartsWith("justfx"))
                {

                    string[] array7 = text.Split(XGlobalConfig.TabSeparator);
                    if (array7.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc8 = new LevelCmdDesc();
                        levelCmdDesc8.cmd = LevelCmd.Level_Cmd_JustFx;
                        levelCmdDesc8.Param.Add(array7[1]);
                        this._LevelScripts[key].Add(levelCmdDesc8);
                    }
                }
                else if (text.StartsWith("playfx"))
                {
                    string[] array8 = text.Split(XGlobalConfig.TabSeparator);
                    if (array8.Length >= 3)
                    {
                        LevelCmdDesc levelCmdDesc9 = new LevelCmdDesc();
                        levelCmdDesc9.cmd = LevelCmd.Level_Cmd_PlayFx;
                        levelCmdDesc9.Param.Add(array8[1]);
                        levelCmdDesc9.Param.Add(array8[2]);
                        this._LevelScripts[key].Add(levelCmdDesc9);
                    }
                }
                else if (text.StartsWith("settutorial"))
                {
                    string[] array9 = text.Split(XGlobalConfig.TabSeparator);
                    if (array9.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc10 = new LevelCmdDesc();
                        levelCmdDesc10.cmd = LevelCmd.Level_Cmd_Tutorial;
                        levelCmdDesc10.Param.Add(array9[1]);
                        this._LevelScripts[key].Add(levelCmdDesc10);
                    }
                }
                else if (text.StartsWith("notice"))
                {

                    string[] array10 = text.Split(XGlobalConfig.TabSeparator);
                    if (array10.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc11 = new LevelCmdDesc();
                        levelCmdDesc11.cmd = LevelCmd.Level_Cmd_Notice;
                        levelCmdDesc11.Param.Add(array10[1]);
                        if (array10.Length >= 3)
                        {
                            levelCmdDesc11.Param.Add(array10[2]);
                        }
                        this._LevelScripts[key].Add(levelCmdDesc11);
                    }
                }
                else if (text.StartsWith("stopnotice"))
                {

                    LevelCmdDesc levelCmdDesc12 = new LevelCmdDesc();
                    levelCmdDesc12.cmd = LevelCmd.Level_Cmd_StopNotice;
                    this._LevelScripts[key].Add(levelCmdDesc12);
                }
                else if (text.StartsWith("opendoor"))
                {
                    string[] array11 = text.Split(XGlobalConfig.TabSeparator);
                    if (array11.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc13 = new LevelCmdDesc();
                        levelCmdDesc13.cmd = LevelCmd.Level_Cmd_Opendoor;
                        levelCmdDesc13.Param.Add(array11[1]);
                        if (array11.Length > 2)
                        {
                            levelCmdDesc13.Param.Add(array11[2]);
                        }
                        this._LevelScripts[key].Add(levelCmdDesc13);
                    }
                }
                else if (text.StartsWith("killspawn"))
                {
                    string[] array12 = text.Split(XGlobalConfig.TabSeparator);
                    if (array12.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc14 = new LevelCmdDesc();
                        levelCmdDesc14.cmd = LevelCmd.Level_Cmd_KillSpawn;
                        levelCmdDesc14.Param.Add(array12[1]);
                        this._LevelScripts[key].Add(levelCmdDesc14);
                    }
                }
                else if (text.StartsWith("killallspawn"))
                {

                    LevelCmdDesc levelCmdDesc15 = new LevelCmdDesc();
                    levelCmdDesc15.cmd = LevelCmd.Level_Cmd_KillAllSpawn;
                    this._LevelScripts[key].Add(levelCmdDesc15);
                }
                else if (text.StartsWith("killallspawn"))
                {
                    LevelCmdDesc levelCmdDesc16 = new LevelCmdDesc();
                    levelCmdDesc16.cmd = LevelCmd.Level_Cmd_KillAlly;
                    this._LevelScripts[key].Add(levelCmdDesc16);
                }
                else if (text.StartsWith("killwave"))
                {
                    string[] array13 = text.Split(XGlobalConfig.TabSeparator);
                    if (array13.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc17 = new LevelCmdDesc();
                        levelCmdDesc17.cmd = LevelCmd.Level_Cmd_KillWave;
                        levelCmdDesc17.Param.Add(array13[1]);
                        this._LevelScripts[key].Add(levelCmdDesc17);
                    }
                }
                else if (text.StartsWith("showcutscene"))
                {
                    string[] array14 = text.Split(XGlobalConfig.TabSeparator);
                    if (array14.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc18 = new LevelCmdDesc();
                        levelCmdDesc18.cmd = LevelCmd.Level_Cmd_Cutscene;
                        levelCmdDesc18.Param.Add(array14[1]);
                        if (array14.Length >= 6)
                        {
                            levelCmdDesc18.Param.Add(array14[2]);
                            levelCmdDesc18.Param.Add(array14[3]);
                            levelCmdDesc18.Param.Add(array14[4]);
                            levelCmdDesc18.Param.Add(array14[5]);
                            if (array14.Length >= 7)
                            {
                                levelCmdDesc18.Param.Add(array14[6]);
                            }
                        }
                        else
                        {
                            if (array14.Length == 3)
                            {
                                levelCmdDesc18.Param.Add(array14[2]);
                            }
                        }
                        this._LevelScripts[key].Add(levelCmdDesc18);
                    }
                }
                else if (text.StartsWith("levelupfx"))
                {

                    LevelCmdDesc levelCmdDesc19 = new LevelCmdDesc();
                    levelCmdDesc19.cmd = LevelCmd.Level_Cmd_LevelupFx;
                    this._LevelScripts[key].Add(levelCmdDesc19);
                }
                else if (text.StartsWith("continue_UI"))
                {

                    LevelCmdDesc levelCmdDesc20 = new LevelCmdDesc();
                    levelCmdDesc20.cmd = LevelCmd.Level_Cmd_Continue;
                    this._LevelScripts[key].Add(levelCmdDesc20);
                }
                else if (text.StartsWith("showskillslot"))
                {
                    string[] array15 = text.Split(XGlobalConfig.TabSeparator);
                    if (array15.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc21 = new LevelCmdDesc();
                        levelCmdDesc21.cmd = LevelCmd.Level_Cmd_ShowSkill;
                        levelCmdDesc21.Param.Add(array15[1]);
                        this._LevelScripts[key].Add(levelCmdDesc21);
                    }
                }
                else if (text.StartsWith("bubble"))
                {
                    string[] array16 = text.Split(XGlobalConfig.TabSeparator);
                    if (array16.Length >= 4)
                    {
                        LevelCmdDesc levelCmdDesc22 = new LevelCmdDesc();
                        levelCmdDesc22.cmd = LevelCmd.Level_Cmd_Bubble;
                        levelCmdDesc22.Param.Add(array16[1]);
                        levelCmdDesc22.Param.Add(array16[2]);
                        levelCmdDesc22.Param.Add(array16[3]);
                        this._LevelScripts[key].Add(levelCmdDesc22);
                    }
                }
                else if (text.StartsWith("showdirection"))
                {
                    string[] array17 = text.Split(XGlobalConfig.TabSeparator);
                    if (array17.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc23 = new LevelCmdDesc();
                        levelCmdDesc23.cmd = LevelCmd.Level_Cmd_Direction;
                        levelCmdDesc23.Param.Add(array17[1]);
                        this._LevelScripts[key].Add(levelCmdDesc23);
                    }
                }
                else if (text.StartsWith("outline"))
                {
                    string[] array18 = text.Split(XGlobalConfig.TabSeparator);
                    if (array18.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc24 = new LevelCmdDesc();
                        levelCmdDesc24.cmd = LevelCmd.Level_Cmd_Outline;
                        levelCmdDesc24.Param.Add(array18[1]);
                        this._LevelScripts[key].Add(levelCmdDesc24);
                    }
                }
                else if (text.StartsWith("clientrecord"))
                {
                    string[] array19 = text.Split(XGlobalConfig.TabSeparator);
                    if (array19.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc25 = new LevelCmdDesc();
                        levelCmdDesc25.cmd = LevelCmd.Level_Cmd_Record;
                        levelCmdDesc25.Param.Add(array19[1]);
                        this._LevelScripts[key].Add(levelCmdDesc25);
                    }
                }
                else if (text.StartsWith("callnewbiehelper"))
                {
                    LevelCmdDesc levelCmdDesc26 = new LevelCmdDesc();
                    levelCmdDesc26.cmd = LevelCmd.Level_Cmd_NewbieHelper;
                    this._LevelScripts[key].Add(levelCmdDesc26);
                }
                else if (text.StartsWith("newbienotice"))
                {
                    string[] array20 = text.Split(XGlobalConfig.TabSeparator);
                    if (array20.Length >= 2)
                    {
                        LevelCmdDesc levelCmdDesc27 = new LevelCmdDesc();
                        levelCmdDesc27.cmd = LevelCmd.Level_Cmd_NewbieNotice;
                        levelCmdDesc27.Param.Add(array20[1]);
                        this._LevelScripts[key].Add(levelCmdDesc27);
                    }
                }
                else if (text.StartsWith("summon"))
                {
                    string[] array21 = text.Split(XGlobalConfig.TabSeparator);
                    if (array21.Length >= 4)
                    {
                        LevelCmdDesc levelCmdDesc28 = new LevelCmdDesc();
                        levelCmdDesc28.cmd = LevelCmd.Level_Cmd_Summon;
                        levelCmdDesc28.Param.Add(array21[1]);
                        levelCmdDesc28.Param.Add(array21[2]);
                        levelCmdDesc28.Param.Add(array21[3]);
                        this._LevelScripts[key].Add(levelCmdDesc28);
                    }
                }
                else if (text.StartsWith("npcpopspeek"))
                {
                    string[] array22 = text.Split(XGlobalConfig.TabSeparator);
                    if (array22.Length >= 5)
                    {
                        LevelCmdDesc levelCmdDesc29 = new LevelCmdDesc();
                        levelCmdDesc29.cmd = LevelCmd.Level_Cmd_NpcPopSpeek;
                        levelCmdDesc29.Param.Add(array22[1]);
                        levelCmdDesc29.Param.Add(array22[2]);
                        levelCmdDesc29.Param.Add(array22[3]);
                        levelCmdDesc29.Param.Add(array22[4]);
                        if (array22.Length >= 6)
                        {
                            levelCmdDesc29.Param.Add(array22[5]);
                        }
                        this._LevelScripts[key].Add(levelCmdDesc29);
                    }
                }
                else if (text.StartsWith("aicommand"))
                {
                    string[] array23 = text.Split(XGlobalConfig.TabSeparator);
                    if (array23.Length >= 3)
                    {
                        LevelCmdDesc levelCmdDesc30 = new LevelCmdDesc();
                        levelCmdDesc30.cmd = LevelCmd.Level_Cmd_SendAICmd;
                        levelCmdDesc30.Param.Add(array23[1]);
                        levelCmdDesc30.Param.Add(array23[2]);
                        if (array23.Length >= 4)
                        {
                            levelCmdDesc30.Param.Add(array23[3]);
                        }
                        else
                        {
                            levelCmdDesc30.Param.Add("0");
                        }
                        this._LevelScripts[key].Add(levelCmdDesc30);
                    }
                }
                else if (text.StartsWith("info"))
                {
                    string[] array24 = text.Split(XGlobalConfig.TabSeparator);
                    string[] array25 = array24[1].Split(XGlobalConfig.ListSeparator);
                    XLevelInfo xlevelInfo = new XLevelInfo();
                    xlevelInfo.infoName = array24[0].Substring(5);
                    xlevelInfo.x = float.Parse(array25[0]);
                    xlevelInfo.y = float.Parse(array25[1]);
                    xlevelInfo.z = float.Parse(array25[2]);
                    xlevelInfo.face = float.Parse(array25[3]);
                    if (array24.Length >= 3)
                    {
                        xlevelInfo.enable = (array24[2] == "on");
                    }
                    if (array24.Length >= 4)
                    {
                        xlevelInfo.width = float.Parse(array24[3]);
                    }
                    if (array24.Length >= 5)
                    {
                        xlevelInfo.height = float.Parse(array24[4]);
                    }
                    else
                    {
                        xlevelInfo.height = float.MaxValue;
                    }
                    if (array24.Length >= 6)
                    {
                        xlevelInfo.thickness = float.Parse(array24[5]);
                    }
                    this._LevelInfos.Add(xlevelInfo);
                }

            }
            XSingleton<XResourceLoaderMgr>.singleton.ClearStream(stream);
        }

        // Token: 0x0600C128 RID: 49448 RVA: 0x0028F874 File Offset: 0x0028DA74
        public List<XLevelInfo> GetLevelScriptInfos()
        {
            return this._LevelInfos;
        }

        // Token: 0x0600C129 RID: 49449 RVA: 0x0028F88C File Offset: 0x0028DA8C
        public void Update()
        {
            //bool flag = this._CmdQueue == null || this._CmdQueue.Count == 0;
            if (/*!flag*/this._CmdQueue != null && this._CmdQueue.Count != 0)
            {
                if (this._currentCmd == null || this._currentCmd.state == XCmdState.Cmd_Finished)
                {
                    this._currentCmd = ((this._CmdQueue.Count > 0) ? this._CmdQueue[0] : null);
                    if (this._currentCmd != null)
                    {
                        this._CmdQueue.RemoveAt(0);
                        this.CommandCount += 1U;
                        this.Execute(this._currentCmd);
                    }
                }
            }
        }

        // Token: 0x0600C12A RID: 49450 RVA: 0x0028F938 File Offset: 0x0028DB38
        public void ExecuteNextCmd()
        {
            if (this._currentCmd != null)
            {
                this._currentCmd.state = XCmdState.Cmd_Finished;
            }
            if (this._CmdQueue.Count == 0)
            {
                this._currentCmd = null;
            }
            else
            {
                this._currentCmd = ((this._CmdQueue.Count > 0) ? this._CmdQueue[0] : null);
                if (this._currentCmd != null)
                {
                    this._CmdQueue.RemoveAt(0);
                    this.Execute(this._currentCmd);
                }
            }
        }

        // Token: 0x0600C12B RID: 49451 RVA: 0x0028F9CB File Offset: 0x0028DBCB
        public void Reset()
        {
            this._externalString.Clear();
            this._onceString.Clear();
            this._CmdQueue.Clear();
            this._currentCmd = null;
            this._LevelScripts.Clear();
        }

        // Token: 0x0600C12C RID: 49452 RVA: 0x0028FA08 File Offset: 0x0028DC08
        protected void Execute(LevelCmdDesc cmd)
        {
            switch (cmd.cmd)
            {
                case LevelCmd.Level_Cmd_TalkL:
                    {
                        if (cmd.Param.Count > 2)
                        {
                            DlgBase<BattleDramaDlg, BattleDramaDlgBehaviour>.singleton.SetLeftAvatar(cmd.Param[0], cmd.Param[1], cmd.Param[2]);
                        }
                        else
                        {
                            DlgBase<BattleDramaDlg, BattleDramaDlgBehaviour>.singleton.SetLeftAvatar(cmd.Param[0], cmd.Param[1], string.Empty);
                        }
                        this._currentCmd.state = XCmdState.Cmd_In_Process;
                        break;
                    }
                case LevelCmd.Level_Cmd_TalkR:
                    {
                        if (cmd.Param.Count > 2)
                        {
                            DlgBase<BattleDramaDlg, BattleDramaDlgBehaviour>.singleton.SetRightAvatar(cmd.Param[0], cmd.Param[1], cmd.Param[2]);
                        }
                        else
                        {
                            DlgBase<BattleDramaDlg, BattleDramaDlgBehaviour>.singleton.SetRightAvatar(cmd.Param[0], cmd.Param[1], string.Empty);
                        }
                        this._currentCmd.state = XCmdState.Cmd_In_Process;
                        break;
                    }
                case LevelCmd.Level_Cmd_Notalk:
                    XSingleton<XLevelSpawnMgr>.singleton.BossExtarScriptExecuting = false;
                    DlgBase<BattleDramaDlg, BattleDramaDlgBehaviour>.singleton.SetVisible(false, true);
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_Addbuff:
                    {
                        XSingleton<XShell>.singleton.Pause = false;
                        int buffID = int.Parse(cmd.Param[1]);
                        int buffLevel = int.Parse(cmd.Param[2]);
                        int num = int.Parse(cmd.Param[0]);
                        if (num == 0)
                        {
                            XBuffAddEventArgs @event = XEventPool<XBuffAddEventArgs>.GetEvent();
                            @event.xBuffDesc.BuffID = buffID;
                            @event.xBuffDesc.BuffLevel = buffLevel;
                            @event.Firer = XSingleton<XEntityMgr>.singleton.Player;
                            @event.xBuffDesc.CasterID = XSingleton<XEntityMgr>.singleton.Player.ID;
                            XSingleton<XEventMgr>.singleton.FireEvent(@event);
                        }
                        else
                        {
                            List<XEntity> opponent = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                            for (int i = 0; i < opponent.Count; i++)
                            {
                                if ((ulong)opponent[i].TypeID == (ulong)((long)num))
                                {
                                    XBuffAddEventArgs event2 = XEventPool<XBuffAddEventArgs>.GetEvent();
                                    event2.xBuffDesc.BuffID = buffID;
                                    event2.xBuffDesc.BuffLevel = buffLevel;
                                    event2.Firer = opponent[i];
                                    event2.xBuffDesc.CasterID = opponent[i].ID;
                                    XSingleton<XEventMgr>.singleton.FireEvent(event2);
                                }
                            }
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Tutorial:
                    {
                        if (XSingleton<XTutorialMgr>.singleton.NeedTutorail)
                        {
                            XSingleton<XTutorialMgr>.singleton.SetExternalString(cmd.Param[0]);
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Notice:
                    {
                        float duration = 3f;
                        if (cmd.Param.Count > 1)
                        {
                            duration = float.Parse(cmd.Param[1]);
                        }
                        if (DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.ShowNotice(cmd.Param[0], duration, 1f);
                        }
                        if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<BattleMain, BattleMainBehaviour>.singleton.ShowNotice(cmd.Param[0], duration, 1f);
                        }
                        if (this._currentCmd != null)
                        {
                            this._currentCmd.state = XCmdState.Cmd_Finished;
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_StopNotice:
                    {
                        if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<BattleMain, BattleMainBehaviour>.singleton.StopNotice();
                        }
                        if (DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.StopNotice();
                        }
                        if (this._currentCmd != null)
                        {
                            this._currentCmd.state = XCmdState.Cmd_Finished;
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_Opendoor:
                    {
                        GameObject gameObject = GameObject.Find(XSingleton<XSceneMgr>.singleton.GetSceneDynamicPrefix(XSingleton<XScene>.singleton.SceneID));
                        Transform transform = XSingleton<XCommon>.singleton.FindChildRecursively(gameObject.transform, cmd.Param[0]);
                        if (transform == null)
                        {
                            XSingleton<XDebug>.singleton.AddErrorLog("Wall no exists: ", cmd.Param[0], null, null, null, null);
                        }
                        if (cmd.Param.Count > 1)
                        {
                            if (cmd.Param[1] == "on")
                            {
                                transform.gameObject.SetActive(true);
                                if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                                {
                                    DlgBase<BattleMain, BattleMainBehaviour>.singleton.IndicateHandler.MiniMapAddDoor(transform);
                                }
                                if (DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded())
                                {
                                    DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IndicateHandler.MiniMapAddDoor(transform);
                                }
                                this.SwitchWallState(cmd.Param[0], true);
                            }
                            else
                            {
                                if (cmd.Param[1].Length == 0 || cmd.Param[1] == "off")
                                {
                                    transform.gameObject.SetActive(false);
                                    this.SwitchWallState(cmd.Param[0], false);
                                }
                            }
                        }
                        else
                        {
                            transform.gameObject.SetActive(false);
                            this.SwitchWallState(cmd.Param[0], false);
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Cutscene:
                    {
                        XSingleton<XDebug>.singleton.AddLog("play cutscene ", cmd.Param[0], null, null, null, null, XDebugColor.XDebug_None);
                        if (cmd.Param.Count == 6)
                        {
                            XSingleton<XCutScene>.singleton.GeneralMonsterID = uint.Parse(cmd.Param[5]);
                        }
                        else
                        {
                            if (cmd.Param.Count == 2)
                            {
                                XSingleton<XCutScene>.singleton.GeneralMonsterID = uint.Parse(cmd.Param[1]);
                            }
                        }
                        if (this.CommandCount == 1U)
                        {
                            XSingleton<XCutScene>.singleton.Start(cmd.Param[0], false, true);
                        }
                        else
                        {
                            XSingleton<XCutScene>.singleton.Start(cmd.Param[0], true, true);
                        }
                        if (cmd.Param.Count >= 5)
                        {
                            float num2 = float.Parse(cmd.Param[1]);
                            float num3 = float.Parse(cmd.Param[2]);
                            float num4 = float.Parse(cmd.Param[3]);
                            XSingleton<XCutScene>.singleton.EndWithDir = float.Parse(cmd.Param[4]);
                            XSingleton<XCutScene>.singleton.EndWithPos = new Vector3(num2, num3, num4);
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_LevelupFx:
                    {
                        XPlayer player = XSingleton<XEntityMgr>.singleton.Player;
                        XSingleton<XFxMgr>.singleton.CreateAndPlay(XSingleton<XGlobalConfig>.singleton.GetValue("LevelupFx"), player.EngineObject, Vector3.zero, Vector3.one, 1f, true, 5f, true);
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_ShowSkill:
                    {
                        int index = int.Parse(cmd.Param[0]);
                        if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<BattleMain, BattleMainBehaviour>.singleton.SkillHandler.ShowSkillSlot(index);
                        }
                        XSingleton<XTutorialHelper>.singleton.MeetEnemy = false;
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_KillSpawn:
                    XSingleton<XDebug>.singleton.AddErrorLog("找小邹: kill spawn", null, null, null, null, null);
                    XSingleton<XLevelSpawnMgr>.singleton.CurrentSpawner.KillSpawn(int.Parse(cmd.Param[0]));
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_KillAlly:
                    XSingleton<XDebug>.singleton.AddErrorLog("找小邹: kill ally", null, null, null, null, null);
                    XSingleton<XEntityMgr>.singleton.KillAlly(XSingleton<XEntityMgr>.singleton.Player);
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_KillWave:
                    {
                        int num5 = int.Parse(cmd.Param[0]);
                        List<XEntity> all = XSingleton<XEntityMgr>.singleton.GetAll();
                        for (int j = 0; j < all.Count; j++)
                        {
                            if (num5 == all[j].Wave)
                            {
                                all[j].Attributes.ForceDeath();
                            }
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Direction:
                    {
                        GameObject gameObject2 = GameObject.Find(XSingleton<XSceneMgr>.singleton.GetSceneDynamicPrefix(XSingleton<XScene>.singleton.SceneID));
                        Transform transform2 = XSingleton<XCommon>.singleton.FindChildRecursively(gameObject2.transform, cmd.Param[0]);
                        if (transform2 != null)
                        {
                            if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                            {
                                DlgBase<BattleMain, BattleMainBehaviour>.singleton.IndicateHandler.ShowDirection(transform2);
                            }
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Outline:
                    {
                        int num6 = int.Parse(cmd.Param[0]);
                        List<XEntity> opponent2 = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                        for (int k = 0; k < opponent2.Count; k++)
                        {
                            if (opponent2[k].Wave == num6)
                            {
                                XHighlightEventArgs event3 = XEventPool<XHighlightEventArgs>.GetEvent();
                                event3.Enabled = true;
                                event3.Firer = opponent2[k];
                                XSingleton<XEventMgr>.singleton.FireEvent(event3);
                            }
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Record:
                    XSingleton<XOperationRecord>.singleton.DoScriptRecord(cmd.Param[0]);
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_Continue:
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_NewbieHelper:
                    {
                        uint num7 = 0U;
                        uint num8 = 0U;
                        uint num9 = 0U;
                        XPlayer player2 = XSingleton<XEntityMgr>.singleton.Player;
                        XBoss boss = XSingleton<XEntityMgr>.singleton.Boss;
                        bool flag27 = player2 == null || boss == null;
                        if (!flag27)
                        {
                            if (num7 > 0U)
                            {
                                XSingleton<XLevelSpawnMgr>.singleton.SpawnExternalMonster(num7, new Vector3(104.3f, 9.93f, 104.5f), 0);
                            }
                            if (num8 > 0U)
                            {
                                XSingleton<XLevelSpawnMgr>.singleton.SpawnExternalMonster(num8, new Vector3(106f, 9.93f, 105f), 0);
                            }
                            if (num9 > 0U)
                            {
                                XSingleton<XLevelSpawnMgr>.singleton.SpawnExternalMonster(num9, new Vector3(103.83f, 9.93f, 101.12f), 0);
                            }
                            if (this._currentCmd != null)
                            {
                                this._currentCmd.state = XCmdState.Cmd_Finished;
                            }
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_NewbieNotice:
                    {
                        if (DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.ShowBigNotice(cmd.Param[0]);
                        }
                        if (DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded())
                        {
                            DlgBase<BattleMain, BattleMainBehaviour>.singleton.ShowBigNotice(cmd.Param[0], true);
                        }
                        if (this._currentCmd != null)
                        {
                            this._currentCmd.state = XCmdState.Cmd_In_Process;
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_Removebuff:
                    {
                        XSingleton<XShell>.singleton.Pause = false;
                        int xBuffID = int.Parse(cmd.Param[1]);
                        int num10 = int.Parse(cmd.Param[0]);
                        if (num10 == 0)
                        {
                            XBuffRemoveEventArgs event4 = XEventPool<XBuffRemoveEventArgs>.GetEvent();
                            event4.xBuffID = xBuffID;
                            event4.Firer = XSingleton<XEntityMgr>.singleton.Player;
                            XSingleton<XEventMgr>.singleton.FireEvent(event4);
                        }
                        else
                        {
                            List<XEntity> opponent3 = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                            for (int l = 0; l < opponent3.Count; l++)
                            {
                                if ((ulong)opponent3[l].TypeID == (ulong)((long)num10))
                                {
                                    XBuffRemoveEventArgs event5 = XEventPool<XBuffRemoveEventArgs>.GetEvent();
                                    event5.xBuffID = xBuffID;
                                    event5.Firer = opponent3[l];
                                    XSingleton<XEventMgr>.singleton.FireEvent(event5);
                                }
                            }
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Summon:
                    {
                        uint enemyID = uint.Parse(cmd.Param[0]);
                        uint num11 = uint.Parse(cmd.Param[2]);
                        Vector3 pos = Vector3.zero;
                        int rot = 0;
                        if (cmd.Param[1] == "[player]")
                        {
                            pos = XSingleton<XEntityMgr>.singleton.Player.EngineObject.Position;
                        }
                        else
                        {
                            int num12 = int.Parse(cmd.Param[1]);
                            List<XEntity> opponent4 = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                            for (int m = 0; m < opponent4.Count; m++)
                            {
                                if ((ulong)opponent4[m].TypeID == (ulong)((long)num12))
                                {
                                    pos = opponent4[m].EngineObject.Position;
                                    rot = (int)opponent4[m].EngineObject.Rotation.eulerAngles.y;
                                }
                            }
                        }
                        int num13 = 0;
                        while ((long)num13 < (long)((ulong)num11))
                        {
                            XSingleton<XLevelSpawnMgr>.singleton.SpawnExternalMonster(enemyID, pos, rot);
                            num13++;
                        }
                        if (this._currentCmd != null)
                        {
                            this._currentCmd.state = XCmdState.Cmd_Finished;
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_KillAllSpawn:
                    XSingleton<XLevelFinishMgr>.singleton.KillAllOpponent();
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_NpcPopSpeek:
                    {
                        int type = int.Parse(cmd.Param[0]);
                        int npcid = int.Parse(cmd.Param[1]);
                        string text = cmd.Param[2];
                        float time = float.Parse(cmd.Param[3]);
                        string fmod = "";
                        if (cmd.Param.Count >= 5)
                        {
                            fmod = cmd.Param[4];
                        }
                        DlgBase<NpcPopSpeekView, DlgBehaviourBase>.singleton.ShowNpcPopSpeek(type, npcid, text, time, fmod);
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_SendAICmd:
                    {
                        int num14 = int.Parse(cmd.Param[0]);
                        string eventArg = cmd.Param[1];
                        int typeId = int.Parse(cmd.Param[2]);
                        List<XEntity> list = new List<XEntity>();
                        if (num14 == -1)
                        {
                            if (XSingleton<XLevelSpawnMgr>.singleton.AIGlobal != null && XSingleton<XLevelSpawnMgr>.singleton.AIGlobal.Host != null)
                            {
                                list.Add(XSingleton<XLevelSpawnMgr>.singleton.AIGlobal.Host);
                            }
                        }
                        else
                        {
                            List<XEntity> ally = XSingleton<XEntityMgr>.singleton.GetAlly(XSingleton<XEntityMgr>.singleton.Player);
                            List<XEntity> opponent5 = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                            for (int n = 0; n < ally.Count; n++)
                            {
                                if (ally[n].Attributes.TypeID == (uint)num14)
                                {
                                    list.Add(ally[n]);
                                }
                            }
                            for (int num15 = 0; num15 < opponent5.Count; num15++)
                            {
                                if (opponent5[num15].Attributes.TypeID == (uint)num14)
                                {
                                    list.Add(opponent5[num15]);
                                }
                            }
                        }
                        for (int num16 = 0; num16 < list.Count; num16++)
                        {
                            XAIEventArgs event6 = XEventPool<XAIEventArgs>.GetEvent();
                            event6.DepracatedPass = false;
                            event6.Firer = list[num16];
                            event6.EventType = 1;
                            event6.EventArg = eventArg;
                            event6.TypeId = typeId;
                            XSingleton<XEventMgr>.singleton.FireEvent(event6, 0.05f);
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_Bubble:
                    XSingleton<XLevelSpawnMgr>.singleton.CurrentSpawner.ShowBubble(int.Parse(cmd.Param[0]), cmd.Param[1], float.Parse(cmd.Param[2]));
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_HideBillboard:
                    {
                        int num17 = int.Parse(cmd.Param[0]);
                        float hidetime = float.Parse(cmd.Param[1]);
                        List<XEntity> opponent6 = XSingleton<XEntityMgr>.singleton.GetOpponent(XSingleton<XEntityMgr>.singleton.Player);
                        for (int num18 = 0; num18 < opponent6.Count; num18++)
                        {
                            if ((ulong)opponent6[num18].TypeID == (ulong)((long)num17))
                            {
                                XBillboardHideEventArgs event7 = XEventPool<XBillboardHideEventArgs>.GetEvent();
                                event7.hidetime = hidetime;
                                event7.Firer = opponent6[num18];
                                XSingleton<XEventMgr>.singleton.FireEvent(event7);
                            }
                        }
                        break;
                    }
                case LevelCmd.Level_Cmd_ChangeBody:
                    {
                        XPlayer player3 = XSingleton<XEntityMgr>.singleton.Player;
                        if (player3 != null)
                        {
                            player3.OnTransform(uint.Parse(cmd.Param[0]));
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                case LevelCmd.Level_Cmd_JustFx:
                    this.DoScriptJustFx(cmd.Param);
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
                case LevelCmd.Level_Cmd_PlayFx:
                    {
                        Transform transform3 = XSingleton<UIManager>.singleton.UIRoot.Find("Camera").transform;
                        if (transform3 != null)
                        {
                            XSingleton<XFxMgr>.singleton.CreateAndPlay(cmd.Param[0], transform3, Vector3.zero, Vector3.one, 1f, true, float.Parse(cmd.Param[1]), true);
                        }
                        this._currentCmd.state = XCmdState.Cmd_Finished;
                        break;
                    }
                default:
                    this._currentCmd.state = XCmdState.Cmd_Finished;
                    break;
            }
        }

        // Token: 0x0600C12D RID: 49453 RVA: 0x00290C94 File Offset: 0x0028EE94
        public void SetExternalString(string str, bool bOnce)
        {
            if (bOnce)
            {
                if (!this._onceString.Contains(str))
                {
                    this._externalString.Add(str);
                    this._onceString.Add(str);
                }
            }
            else
            {
                this._externalString.Add(str);
            }
        }

        // Token: 0x0600C12E RID: 49454 RVA: 0x00290CE8 File Offset: 0x0028EEE8
        public bool QueryExternalString(string str, bool autoRemove)
        {
            bool flag = false;
            foreach (string a in this._externalString)
            {
                if (a == str)
                {
                    flag = true;
                    break;
                }
            }
            if (flag && autoRemove)
            {
                this._externalString.Remove(str);
            }
            return flag;
        }

        // Token: 0x0600C12F RID: 49455 RVA: 0x00290D6C File Offset: 0x0028EF6C
        public bool IsTalkScript(string funcName)
        {
            bool result;
            if (!this._LevelScripts.ContainsKey(funcName))
            {
                XSingleton<XDebug>.singleton.AddErrorLog("invalid script func", null, null, null, null, null);
                result = false;
            }
            else
            {
                LevelCmdDesc levelCmdDesc = this._LevelScripts[funcName][0];
                bool flag2 = levelCmdDesc.cmd == LevelCmd.Level_Cmd_TalkL || levelCmdDesc.cmd == LevelCmd.Level_Cmd_TalkR;
                result = flag2;
            }
            return result;
        }

        // Token: 0x0600C130 RID: 49456 RVA: 0x00290DE0 File Offset: 0x0028EFE0
        protected void SwitchWallState(string name, bool enabled)
        {
            for (int i = 0; i < this._LevelInfos.Count; i++)
            {
                if (this._LevelInfos[i].infoName == name)
                {
                    this._LevelInfos[i].enable = enabled;
                }
            }
        }

        // Token: 0x0600C131 RID: 49457 RVA: 0x00290E39 File Offset: 0x0028F039
        public void SyncWallState(string name, bool isOn)
        {
            this.SetClientWallState(name, isOn);
            this.SwitchWallState(name, isOn);
        }

        // Token: 0x0600C132 RID: 49458 RVA: 0x00290E50 File Offset: 0x0028F050
        public void SetClientWallState(string name, bool isOn)
        {
            GameObject gameObject = GameObject.Find(XSingleton<XSceneMgr>.singleton.GetSceneDynamicPrefix(XSingleton<XScene>.singleton.SceneID));
            if (gameObject != null)
            {
                Transform transform = XSingleton<XCommon>.singleton.FindChildRecursively(gameObject.transform, name);
                if (transform == null)
                {
                    XSingleton<XDebug>.singleton.AddErrorLog("Wall no exists: ", name, null, null, null, null);
                }
                else
                {
                    transform.gameObject.SetActive(isOn);
                }
            }
        }

        // Token: 0x0600C133 RID: 49459 RVA: 0x00290EC8 File Offset: 0x0028F0C8
        public void ResetAirWallState()
        {
            for (int i = 0; i < this._LevelInfos.Count; i++)
            {
                this.SetClientWallState(this._LevelInfos[i].infoName, this._LevelInfos[i].enable);
            }
        }

        // Token: 0x0600C134 RID: 49460 RVA: 0x00290F1C File Offset: 0x0028F11C
        public void DoScriptJustFx(List<string> param)
        {
            float time = float.Parse(param[0]);
            XBattleDocument specificDocument = XDocuments.GetSpecificDocument<XBattleDocument>(XBattleDocument.uuID);
            int num = 1 << LayerMask.NameToLayer("Resources");
            num |= 1 << LayerMask.NameToLayer("QualityHigh");
            num |= 1 << LayerMask.NameToLayer("QualityNormal");
            num |= 1 << LayerMask.NameToLayer("QualityCullDistance");
            specificDocument.SetCameraLayer(num, time);
        }

        // Token: 0x04005167 RID: 20839
        public uint CommandCount = 0U;

        // Token: 0x04005168 RID: 20840
        private List<LevelCmdDesc> _CmdQueue = new List<LevelCmdDesc>();

        // Token: 0x04005169 RID: 20841
        private LevelCmdDesc _currentCmd;

        // Token: 0x0400516A RID: 20842
        public List<string> _externalString = new List<string>();

        // Token: 0x0400516B RID: 20843
        public List<string> _onceString = new List<string>();

        // Token: 0x0400516C RID: 20844
        private Dictionary<string, List<LevelCmdDesc>> _LevelScripts = new Dictionary<string, List<LevelCmdDesc>>();

        // Token: 0x0400516D RID: 20845
        private List<XLevelInfo> _LevelInfos = new List<XLevelInfo>();
    }
}
